/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: jse2303 - Reg4
 * <p>Powered by webrx On 2023-07-18 10:47:41
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reg4 {
    public static void main(String[] args) {
        String hs = """
                <div>java8.0</div><p><div>java</div><p><div> hello java </div><p>java<p> <div>php</div><div>javascript</div> <div><br><p>hello</p></div><div>myjava</div>
                """;
        //在字符串中，取出有java字符的div 禁用贪婪是在量词 * +后添加一个?
        //Pattern p = Pattern.compile("<div>.*java.*</div>");
        //Pattern p = Pattern.compile("<div>.*?java.*?</div>");
        Pattern p = Pattern.compile("<div>([^<>]*?java[^<>]*?)</div>");
        Matcher m = p.matcher(hs);
        while (m.find()) {
            //System.out.println(m.group());
            System.out.println(m.group(1));
            //System.out.println(m.group().replaceAll("<div>", "").replaceAll("</div>", ""));
        }

        System.out.println(hs);
        System.out.println(hs.replaceAll("<div>([^<>]*?java[^<>]*?)</div>", "<span>修改后:$1</span>"));
    }
}
